package _2字符串类;

import java.util.Arrays;
import java.util.Scanner;

public class StringDemo {
	public static void main(String[] args)
	{
		
//		//�ַ����Ĳ���
//		// 1. ����
//		create();
//		
//		// 2. ����
//		input();
//		
//		// 3.�Ƚ�
//		compare();
//		
//		// 4.ת��
//		trans();
		
		// 5.�������
		op();
	}
	
	private static void op() {
		
		// ����
				String str1 = "asdfabcr234d_abcd_faser2345asd_abcd_fadsfasdfasdf";
				System.out.println(str1.indexOf("abcd"));//
				System.out.println(str1.indexOf("abcd",80));
				System.out.println(str1.lastIndexOf("abcd"));
				
				// �滻 �õ�һ���µ��ַ�������û�иı�str1
				System.out.println(str1.replace("abcd", "xxxx"));
				System.out.println(str1);
				
				// �ָ�
				String str2 = "java-c++-python-c#";
				String[] strs = str2.split("-");
				System.out.println(Arrays.toString(strs));
				
				
				// ��ȡ
				String str3 = "abcdefghijk";
				System.out.println(str3.substring(3));
				System.out.println(str3.substring(3,3+4));
	}
	
	private static void trans() {
		String str1 = "Hello";
		char[] chs = str1.toCharArray();
		System.out.println(Arrays.toString(chs));
		
		int n = Integer.parseInt("123");
		System.out.println(n+1);
		float f = Float.parseFloat("12.5");
		System.out.println(f+0.5F);
	}
	
	private static void compare()
	{
		System.out.println("a".compareTo("b"));//-1
		System.out.println("ab".compareTo("ab"));//0
		System.out.println("aac".compareTo("aab"));//1
		
		String str1 = "Demo1.java";
		System.out.println(str1.startsWith("Demo"));
		System.out.println(str1.endsWith(".java"));
	}
	
	private static void input()
	{
		Scanner sc = new Scanner(System.in);
//		String name = sc.next();
//		String tel = sc.next();
		
		String name = sc.nextLine();
		String tel = sc.nextLine();
		System.out.println(name+","+tel);
	}
	
	
	private static void create() {
		// TODO Auto-generated method stub
		
		String str1 = "abc";// �ַ������������ַ�������
		String str2 = ""; // ���ݳ���Ϊ0���ַ���
		String str3 = new String("abc");
		String str4 = null;
		String str5 = "abc";
		String str6 = new String("abc");
		
		// == �Ƚϵ��Ƿ���ͬһ����
		System.out.println(str1 == str5);// true
		System.out.println(str1 == str3);// false
		System.out.println(str3 == str6);// false
		
		// equals�Ƚ�����
		System.out.println(str1.equals(str5));
		System.out.println(str1.equals(str3));
		System.out.println(str3.equals(str6));
		
		System.out.println(str1.length());
		
		char[] chs = {'H','e','l','l','o'};
		String str7 = new String(chs);
		System.out.println(str7);
		String str8 = new String(chs,1,3);
		System.out.println(str8);
		
		byte[] bytes = {104,111,109,100};
		String str9 = new String(bytes);
		System.out.println(str9);
		
	}
	
}
